package com.sun.lib_compress.provider;

import android.content.Context;
import android.net.Uri;

import com.sun.lib_compress.InputStreamProvider;
import com.sun.lib_compress.util.UriUtils;

import java.io.IOException;
import java.io.InputStream;

/*
 *
 * #                                                   #
 * #                       _oo0oo_                     #
 * #                      o8888888o                    #
 * #                      88" . "88                    #
 * #                      (| -_- |)                    #
 * #                      0\  =  /0                    #
 * #                    ___/`---'\___                  #
 * #                  .' \\|     |# '.                 #
 * #                 / \\|||  :  |||# \                #
 * #                / _||||| -:- |||||- \              #
 * #               |   | \\\  -  #/ |   |              #
 * #               | \_|  ''\---/''  |_/ |             #
 * #               \  .-\__  '-'  ___/-. /             #
 * #             ___'. .'  /--.--\  `. .'___           #
 * #          ."" '<  `.___\_<|>_/___.' >' "".         #
 * #         | | :  `- \`.;`\ _ /`;.`/ - ` : | |       #
 * #         \  \ `_.   \_ __\ /__ _/   .-` /  /       #
 * #     =====`-.____`.___ \_____/___.-`___.-'=====    #
 * #                       `=---='                     #
 * #     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   #
 * #                                                   #
 * #               佛祖保佑         永无BUG              #
 * #                                                   #
 */

/**
 * Created by ESSC07 on 2021/12/31.
 */
public class UriStreamProvider implements InputStreamProvider {
    private Uri mUri;
    private Context context;

    public UriStreamProvider(Context context, Uri mUri) {
        this.context = context;
        this.mUri = mUri;
    }

    @Override
    public InputStream open() throws IOException {
        return context.getContentResolver().openInputStream(mUri);
    }

    @Override
    public String getPath() {
        return UriUtils.uri2File(context,mUri).getAbsolutePath();
    }
}
